home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-4641
/
spritefx
/
source
/
example.s
< prev
next >
Wrap
Text File
|
1994-05-12
|
18KB
|
679 lines
********************************************************************
********************************************************************
* This is an example programe using files created with SPRITEFX
* and uses routines that are fairly simple so as to be suitable
* for beginers. For this reason and because of the fact that the
* sprite routine is universal, handling multiple size sprites,
* the routines have not been optimised for maximum speed. Also
* the routines are set up to use only variable speed sequence
* files with frame numbers going from low to high and X/Y only
* path files. Full save and restore has been implemented on the
* background which is not always nessecary or could be acheived
* by other, faster methods but as mentioned above this file was
*created with beginers in mind. More advanced methods and routines
* have been used in the programe in the demo folder, the source
* code for which can be obtained with the registered version of
* SPRITEFX, please read "reg.txt" on disk. For more details on
* using SPRITEFX files within your own programes read the manule
* in the "docs" folder.
********************************************************************
************************ FILE INFORMATION **************************
* For more detailed information on the following files please read
* SPRITEFX.DOC in the MANUAL folder. The ghost sprites where created
* by using the same sprite screen loaded into SPRITEFX then turning
* off planes 1 and 4 and saving as such.
********************************************************************
* PATH FILES *
* _
* 1 WORD * SPRITEFX INFORMATION |-HEADER
* 1 LONGWORD * NUMBER OF X/Y POSITIONS _|
* _
* 1 WORD * X POSITION |-DATA
* 1 WORD * Y POSITION _|
*
* PREVIOUS DATA STRUCTURE TO END OF FILE
*
********************************************************************
*
* SEQUENCE FILES *
* _
* 1 LONGWORD * SPRITEFX INFORMATION |-HEADER
* 1 WORD * SPRITEFX INFORMATION |
* 1 longWORD * NUMBER OF SEQUENCES _|
* _
* 1 WORD * FRAME UPDATE SPEED |-DATA
* 1 WORD * START FRAME NUMBER |
* 1 WORD * END FRAME NUMBER _|
*
* PREVIOUS DATA STRUCTURE TO END OF FILE
* FILE IS TERMINATED WITH -1
*
********************************************************************
*
* SPRITE FILES *
* _
* 1 WORD * SPRITEFX INFORMATION |-HEADER
* 1 WORD * SPRITEFX INFORMATION |
* 1 LONGWORD * NUMBER OF SPRITES |
* 32 WORDS * SPRITE PALETTE DATA _|
* _
* 1 WORD * MASK DATA |-DATA
* 1 WORD * PLANE 1 SPRITE DATA |
* 1 WORD * PLANE 2 SPRITE DATA |
* 1 WORD * PLANE 3 SPRITE DATA |
* 1 WORD * PLANE 4 SPRITE DATA _|
*
* PREVIOUS DATA STRUCTURE TO END OF FILE
*
********************************************************************
* KEYS:- Esc = rerun animation.
* Space = quit program.
********************************************************************
start clr.l -(sp) supervisor mode on
move.w #$20,-(sp)
trap #1
move.l d0,savereg old stack address
lea stack,a7 new stack address
mouseoff
move #$12,-(sp) disable mouse reporting
move #4,-(sp)
move #3,-(sp)
trap #13
addq.l #6,sp
dc.w $A00A Line-A hide mouse
cursor_off
clr.w -(sp)
move.w #21,-(sp)
trap #14
addq.l #4,sp
move.w $484,sav_484
bclr #0,$484 no key click
bclr #1,$484 no repeat key
move.w #4,-(sp) get current resolution
trap #14
addq.l #2,sp
move.w d0,oldrez and save it
move.w #3,-(sp) get current screen
trap #14
addq.l #2,sp
move.l d0,oldscr and save it
movem.l $ffff8240.w,d0-d7 save colors...
movem.l d0-d7,syspal ..quickly
movem.l spritedata+8,d0-d7 * +8 to skip header
movem.l d0-d7,$ffff8240.w new palette
move.l #screen1,d0 get new physical screen
add.l #256,d0
and.l #$ffffff00,d0
move.l d0,phys stored address
move.l #screen2,d0 and new logical screen
add.l #256,d0
and.l #$ffffff00,d0
move.l d0,log stored address
openfile * load back drop Degas picture
move.w #0,-(sp)
move.l #picture,-(sp)
move.w #$3d,-(sp)
trap #1
addq.l #8,sp
tst.w d0
bmi exit
move.w d0,handle
loadpalette
move.l #palette,-(sp)
move.l #34,-(sp)
move.w handle,-(sp)
move.w #$3f,-(sp)
trap #1
add.l #12,sp
loadpicture
move.l #picbuffer,-(sp)
move.l #32000,-(sp)
move.w handle,-(sp)
move.w #$3f,-(sp)
trap #1
add.l #12,sp
close move.w handle,-(sp)
move.w #$3c,-(sp)
trap #1
addq.l #4,sp
move.w #0,-(sp) set low rez
move.l phys,-(sp) phys
move.l log,-(sp) log
move.w #5,-(sp)
trap #14
add.l #12,sp
******************************************************************
* The main programe starts here, if any changes are made or code
* added it may be better to dissable the re-run animation function
* by deleting the check for space being pressed.
******************************************************************
copyscreens
lea picbuffer,a0
move.l phys,a1
move.l #4000-1,d0
.copy1 move.l (a0)+,(a1)+ to physical screen
move.l (a0)+,(a1)+
dbra d0,.copy1
lea picbuffer,a0
move.l log,a1
move.l #4000-1,d0
.copy2 move.l (a0)+,(a1)+ to logical screen
move.l (a0)+,(a1)+
dbra d0,.copy2
* create sprite address table
move.l spritedata+4,d0 number of sprites in the file
subq.l #1,d0
lea sprite_table,a0
lea spritedata+8+32,a1 first sprite block
.loop move.l a1,(a0)+
addq.l #8,a1 skip hight/width/length
add.l -4(a1),a1 add length to current position
dbra d0,.loop
clr.l data_buffer_1a * clear begining of data buffers
clr.l back_buffer_1a
clr.l data_buffer_2b
clr.l back_buffer_2b
move.l #data_buffer_1a,datbuf1 * and store addresses
move.l #back_buffer_1a,bakbuf1
move.l #data_buffer_2b,datbuf2
move.l #back_buffer_2b,bakbuf2
* set up variables
clr.b video mainly for re-run function
move.l #sequence+10,seq_pos
move.l #path+6,pathpos
move.l seq_pos,a0 position in the sequence file
move.w (a0)+,delay frame update delay
move.w delay,countdown
move.w (a0)+,frame sequence start
move.w (a0)+,seqend sequence end
sync
move.w #37,-(sp) xbios vsync
trap #14
addq.l #2,sp
move.w #$ff,-(sp) gemdos rawconio
move.w #6,-(sp)
trap #1
addq.l #4,sp
cmpi.b #27,d0 Esc ? if so quit
beq exit
cmpi.b #' ',d0 Space ? if so re-run
beq copyscreens
cmp.l #path1end,pathpos at end of current path?
blt update if not then update possition
bra anim2 if so the do next animation
update move.l pathpos,a0 currnet position in the path file
add.l #4,pathpos increment position
move.w (a0)+,x_pos get X position
move.w (a0),y_pos get Y position
tst.w countdown end of delay?
bpl .ok2 no then continue
addq.w #1,frame yes so increment frame number
move.w seqend,d0 last frame number in the sequence
cmp.w frame,d0 last frame in the sequence?
blt .nxtseq yes so reset variables
move.w delay,countdown no so just reset frame delay
bra .ok2 and continue
.nxtseq add.l #6,seq_pos get next sequence
move.l seq_pos,a0 position in the sequence file
tst.w (a0) at end of sequence file?
bpl .ok if no then continue
bra anim2 if yes then go to animation 2
.ok move.l seq_pos,a0 position in the sequence file
move.w (a0)+,delay frame update delay
move.w delay,countdown and reset delay couter
move.w (a0)+,frame sequence start
move.w (a0)+,seqend sequence end
.ok2 subq.w #1,countdown decrement delay counter
move.w frame,d0 current frame number
asl.w #2,d0 multiply by 4
lea sprite_table,a0 sprite addresses
move.l 0(a0,d0.w),a0 correct sprite block
move.w (a0)+,hight
move.w (a0)+,width
addq.l #4,a0 skip length
move.l a0,sprite store address of sprite
bsr sprite_routine
bsr swapscreens
bra sync
anim2
* create new sprite address table
move.l ghostdata+4,d0 number of sprites in the file
subq.l #1,d0
lea sprite_table,a0
lea ghostdata+8+32,a1 first sprite block
.loop move.l a1,(a0)+
addq.l #8,a1 skip hight/width/length
add.l -4(a1),a1 add length to current position
dbra d0,.loop
clr.l data_buffer_1a
clr.l back_buffer_1a
clr.l data_buffer_2b
clr.l back_buffer_2b
move.l #path2+6,pathpos
move.l #sequence2+10,seq_pos
move.l seq_pos,a0 position in the sequence file
move.w (a0)+,delay frame update delay
move.w delay,countdown
move.w (a0)+,frame sequence start
move.w (a0)+,seqend sequence end
clr.b video
sync2
move.w #37,-(sp)
trap #14
addq.l #2,sp
move.w #$ff,-(sp)
move.w #6,-(sp)
trap #1
addq.l #4,sp
cmpi.b #27,d0 Esc ? if so quit
beq exit
cmpi.b #' ',d0
beq copyscreens
cmp.l #path2end,pathpos
blt update2
bra anim3
update2 move.l pathpos,a0
add.l #4,pathpos
move.w (a0)+,x_pos
move.w (a0),y_pos
tst.w countdown end of delay?
bpl .ok2
addq.w #1,frame yes so increment frame number
move.w seqend,d0
cmp.w frame,d0 last frame in the sequence?
blt .nxtseq yes so reset variables
move.w delay,countdown no so just reset frame delay
bra .ok2
.nxtseq add.l #6,seq_pos get next sequence
move.l seq_pos,a0 position in the sequence file
move.w (a0)+,delay frame update delay
move.w delay,countdown
move.w (a0)+,frame sequence start
move.w (a0)+,seqend sequence end
bra anim3 go to animation 3
.ok2 subq.w #1,countdown
move.w frame,d0
asl.w #2,d0
lea sprite_table,a0
move.l 0(a0,d0.w),a0 correct sprite block
move.w (a0)+,hight
move.w (a0)+,width
addq.l #4,a0 skip length
move.l a0,sprite
bsr sprite_routine
bsr swapscreens
bra sync2
anim3
sync3
move.w #37,-(sp)
trap #14
addq.l #2,sp
move.w #$ff,-(sp)
move.w #6,-(sp)
trap #1
addq.l #4,sp
cmpi.b #27,d0 Esc ? if so quit
beq exit
cmpi.b #' ',d0
beq copyscreens
add.w #1,x_pos
cmp.w #319,x_pos
ble .y
clr.w x_pos
.y move.w #142,y_pos
tst.w countdown end of delay?
bpl .ok2
addq.w #1,frame yes so increment frame number
move.w seqend,d0
cmp.w frame,d0 last frame in the sequence?
blt .nxtseq yes so reset variables
move.w delay,countdown no so just reset frame delay
bra .ok2
.nxtseq add.l #6,seq_pos get next sequence
move.l seq_pos,a0
tst.w (a0) at end of sequence file?
bpl .ok if no then continue
move.l #sequence2+16,seq_pos skip header and first sequence
.ok move.l seq_pos,a0 position in the sequence file
move.w (a0)+,delay frame update delay
move.w delay,countdown
move.w (a0)+,frame sequence start
move.w (a0)+,seqend sequence end
.ok2 subq.w #1,countdown
move.w frame,d0
asl.w #2,d0
lea sprite_table,a0
move.l 0(a0,d0.w),a0 correct sprite block
move.w (a0)+,hight
move.w (a0)+,width
addq.l #4,a0 skip length
move.l a0,sprite
bsr sprite_routine
bsr swapscreens
bra sync3
exit
move.w sav_484,$484
; bset #0,$484
; bset #1,$484
movem.l syspal,d0-d7 old colors back
movem.l d0-d7,$ffff8240.w
move.w oldrez,-(sp) old resolution back
move.l oldscr,-(sp)
move.l oldscr,-(sp)
move.w #5,-(sp)
trap #14
add.l #12,sp
mouseon
move #8,-(sp) enable mouse reporting
move #4,-(sp)
move #3,-(sp)
trap #13
addq.l #6,sp
dc.w $A009 Line-A show mouse
cursor_on
move.w #1,-(sp)
move.w #21,-(sp)
trap #14
addq.l #4,sp
move.l savereg,-(sp)
move.w #$20,-(sp)
trap #1
addq.l #6,sp
clr.w -(sp)
trap #1
***************************
waitkey
move.w #7,-(sp)
trap #1
addq.l #2,sp
rts
***************************
swapscreens
btst #0,video
beq set_1
set
move.w #-1,-(sp)
move.l log,-(sp)
move.l phys,-(sp)
move.w #5,-(sp)
trap #14
lea 12(sp),sp
bchg #0,video
rts
set_1
move.w #-1,-(sp)
move.l phys,-(sp)
move.l log,-(sp)
move.w #5,-(sp)
trap #14
lea 12(sp),sp
bchg #0,video
rts
******************************************
* UNIVERSAL SPRITE ROUTINE.
* HANDLES MULTIPLE SIZE SPRITES
* WITH CLIPPING ON THE LOWER BORDER.
* MINIMUM SIZE 1 PIXEL HIGH BY 16 WIDE.
* WIDTH MUST BE A MULTIPLE OF 16.
******************************************
dummy dc.b 0 not used
video dc.b 0 screen toggle flag
log dc.l 0 logical screen address
phys dc.l 0 physical screen address
x_pos dc.w 0 absolute X screen position 0-319
y_pos dc.w 0 absolute Y screen position 0-199
hight dc.w 0 sprite hight
width dc.w 0 sprite width
sprite dc.l 0 sprite data address
datbuf1 dc.l 0 buffer 1. Used by sprite routine
bakbuf1 dc.l 0 address of background restore buffer 1
datbuf2 dc.l 0 buffer 2. Used by sprite routine
bakbuf2 dc.l 0 address of background restore buffer 2
sprite_routine
* putback *
btst #0,video
bne res2
res1 move.l datbuf1,a2
move.l bakbuf1,a1
bra dores
res2 move.l datbuf2,a2
move.l bakbuf2,a1
dores
tst.l (a2)
beq ex_put
move.l (a2)+,a0
move.l (a2)+,d7
move.l (a2),d4
asr.w #3,d4 divide by 8
putloop
move.l d4,d5
put
move.l (a1)+,(a0)+
move.l (a1)+,(a0)+
dbra d5,put
lea 160-8(a0),a0
sub.l (a2),a0
dbra d7,putloop
ex_put
* getback *
btst #0,video
bne gbuff2
gbuff1 move.l datbuf1,a2
move.l bakbuf1,a0
move.l phys,a1
bra doget
gbuff2 move.l datbuf2,a2
move.l bakbuf2,a0
move.l log,a1
doget
move.w x_pos,d0
move.w y_pos,d1
mulu.w #160,d1
lea 0(a1,d1.w),a1 draw on this line
moveq #0,d6
move.w d0,d6 save X possition
lsr.w #1,d0 divide by 2
and.w #$fff8,d0 bring to lower 16 boundry
lea 0(a1,d0.w),a1 correct screen position
move.l a1,(a2)+ save address for restore
and.w #$000f,d6 get shift amount in lower 4 bits (0-15)
moveq.l #0,d7
move.w hight,d7
move.w #199,d5 hight of screen
sub.w d7,d5 subtract sprite hight from screen hight
cmp y_pos,d5 is its full hight on screen
bhi .noclip if so don't clip hight.If not...
move.l #199,d7 ...find how much is still on screen
sub.w y_pos,d7 move it to loop counter
.noclip
subq.l #1,d7
move.l d7,(a2)+ to restor counter
moveq.l #0,d4
move.w width,d4
asr.w d4 divide by 8
move.l d4,(a2) to restor counter
asr.w #3,d4 divide by 8
hightloop
move.l d4,d5
widthloop
move.l (a1)+,(a0)+
move.l (a1)+,(a0)+
dbra d5,widthloop
lea 160-8(a1),a1
sub.l (a2),a1
dbra d7,hightloop
* putsprite *
btst #0,video
bne pbuff2
pbuff1 move.l datbuf1,a2
bra doput
pbuff2 move.l datbuf2,a2
doput
move.l sprite,a0 sprite data address
move.l (a2)+,a1 screen address
move.l (a2)+,d7 line loop counter
sprite_draw
move.l (a2),d5 width loop counter
asr.w #3,d5 divide by 8
subq.l #1,d5
spritedraw
moveq #-1,d0
moveq #0,d1
moveq #0,d2
moveq #0,d3
moveq #0,d4
move.w (a0)+,d0 * mask
move.w (a0)+,d1 * plane 1
move.w (a0)+,d2 * plane 2
move.w (a0)+,d3 * plane 3
move.w (a0)+,d4 * plane 4
ror.l d6,d0 * shift mask and planes into place
ror.l d6,d1
ror.l d6,d2
ror.l d6,d3
ror.l d6,d4
and.w d0,(a1) * lay down the mask and data
or.w d1,(a1)+
and.w d0,(a1)
or.w d2,(a1)+
and.w d0,(a1)
or.w d3,(a1)+
and.w d0,(a1)
or.w d4,(a1)+
swap d0
swap d1
swap d2
swap d3
swap d4
and.w d0,(a1)
or.w d1,(a1)+
and.w d0,(a1)
or.w d2,(a1)+
and.w d0,(a1)
or.w d3,(a1)+
and.w d0,(a1)
or.w d4,(a1)+
lea -8(a1),a1
dbra d5,spritedraw
lea 160(a1),a1
sub.l (a2),a1
dbra d7,sprite_draw
rts
oldrez dc.w 0 * old system resolution
oldscr dc.l 0 * old system screen address
savereg dc.l 0 * old stack address
sav_484 dc.w 0 * saved system vaiable (key click/repeat)
handle dc.w 0 * file handle
pathpos dc.l path+6 * +10 to skip header
seq_pos dc.l sequence+10 * +10 to skip header
delay dc.w 0 * frame delay store
countdown * frame delay countdown
dc.w 0 * delay countdown
frame dc.w 0 * current frame number in the sequence
seqend dc.w 0 * last frame number in the sequence
picture dc.b 'a:\spritefx\source\backdrop.pi1',0
***************************************************
***************************************************
* Following binary files included at assembly time.
* Alternatively, ascii versions of these files can
* be combined with the source code. These files are
* also on disk but remember to change the routines
* to suit these files eg. #sequence+10 to #sequence
* because of the absence of header data.
***************************************************
***************************************************
spritedata
incbin a:\spritefx\source\sprites.spr
ghostdata
incbin a:\spritefx\source\ghost.spr
sequence
incbin a:\spritefx\source\sprites.seq
sequence2
incbin a:\spritefx\source\ghost.seq
path incbin a:\spritefx\source\sprites.plt
path1end
path2 incbin a:\spritefx\source\ghost.plt
path2end
***************************************************
***************************************************
section bss
syspal ds.b 32
palette ds.b 34
data_buffer_1a
ds.l 4 screen 1 data
data_buffer_2b
ds.l 4 screen 2 data
back_buffer_1a
ds.b 256*16 screen 1 background save buffer
back_buffer_2b
ds.b 256*16 screen 2 background save buffer
sprite_table * Table of sprite addresses
ds.l 16 * Number of sprites. Adjust as nessecary
picbuffer
ds.b 32000
screen1 ds.b 32000+256
screen2 ds.b 32000+256
even
**********************************
ds.w 512
stack ds.l 0